package fileExercise;

import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;

/**
 * @classname:ConverStreamDemo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/17 22:43
 * @version: 0.1
 * @since:1.8
 */
public class ConverStreamDemo {
    public static void main(String[] args) {
        String novelPath = "https://read.qidian.com/chapter/4VXyfoLH2rZrNWkNCb7tfg2/XFZvT0bg7MX4p8iEw--PPw2";
        testZhuanHuan(novelPath);
    }

    private static void testZhuanHuan(String novelPath) {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(novelPath).openStream(), Charset.forName("UTF-8")));
                BufferedWriter writer = new BufferedWriter(new FileWriter("day16/src/dis/novel.txt"));
        ) {

            String content = "";
            while ((content = reader.readLine()) != null) {
                if (content.contains(" <div class=\"read-content j_readContent\" id=\"\">")) {
                    content = reader.readLine();
                    content = content.replaceAll("<p>","\n");
                    writer.write(content);
                    break;
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
